package com.matt.order.controller;

import com.matt.order.dto.CustomerDto;
import com.matt.order.dto.OrderDto;
import com.matt.order.dto.PlayWithDto;
import com.matt.order.service.OrderEnterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/orderEnter")
public class OrderEnterController {

    @Autowired
    OrderEnterService orderEnterService;

    @RequestMapping("/init")
    public String orderEnterInit(Model model, OrderDto orderDto) {

        List<PlayWithDto> playList = orderEnterService.playWithNameList();
        List<CustomerDto> customerList = orderEnterService.customerNameList();
        OrderDto orderDtoInfo = new OrderDto();
        if ("1".equals(orderDto.getReadOnlyFlg())) {
            orderDtoInfo = orderEnterService.getOrderInfoByOrderId(orderDto);
            orderDtoInfo.setReadOnlyFlg("1");
        }
        model.addAttribute("orderDtoInfo",orderDtoInfo);
        model.addAttribute("playList",playList);
        model.addAttribute("customerList",customerList);
        return "order/order-enter";
    }

    /**
     * 订单信息录入
     * @param model
     * @return
     */
    @RequestMapping("/insertOrderInfo")
    @ResponseBody
    public Map<String, Object> customerInfoInsert(Model model, OrderDto orderDto) {
        Map<String, Object> res = new HashMap<>();
        orderEnterService.orderInfoInsert(orderDto);
        res.put("code", 200);
        return res;
    }
}
